<template>
  <div class="rank">
    <scroll class="toplist" :data="rankList">
      <ul>
        <li class="item" v-for="list in rankList" :key="list.picUrl"  @click="selectItem(list)" >
          <div class="icon">
            <img width="100" height="100" v-lazy="list.picUrl">
          </div>
          <ul class="songlist">
            <li class="song" v-for="it in list.songList" :key = "it.songname" >
              <span>{{it.songname}}</span>
              <span>{{it.singername}}</span>
            </li>
          </ul>
        </li>
      </ul>
    </scroll>
    <router-view></router-view>
  </div>
</template>

<script type="text/ecmascript-6">
  import Scroll from '../../base/scroll/scroll.vue'
  import { getRanking } from '../../api/rank'
  import SongList from '../../base/song-list/song-list.vue'
  import { ERR_OK } from '../../api/config'
  import { mapMutations } from 'vuex'
  // import { createRankSongs } from '../../common/js/song'

  export default {
    data () {
      return {
        rankList: []
      }
    },
    created () {
      this._getRinkList()
    },
    methods: {
      _getRinkList () {
        getRanking((res) => {
          if (res.data.code === ERR_OK) {
            this.rankList = res.data.data.topList
           // console.log(this.rankList)
          }
        })
      },
      selectItem (item) {
       this.$router.push({
         path: `/rank/${item.id}`
       })
        this.setTopList(item)
      },
      ...mapMutations({
        setTopList: 'SET_TOP_LIST'
      })
//      _normalLizeList (songs) {
//        let ret = []
//        songs.forEach((item) => {
//          if (item.songId) {
//            ret.push(createRankSongs(item))
//          }
//        })
//         return ret
//      },
//      selectItem (item, index) {
//        this.selectPlay({
//          list: this.rankList,
//          index
//        })
//      },
//      ...mapActions([
//        'selectPlay'
//      ])
    },
    components: {
      Scroll,
      SongList
    }
  }
</script>

<style scoped lang="stylus" rel="stylesheet/stylus">
  @import "../../common/stylus/variable.styl";
  @import "../../common/stylus/mixin.styl";

  .rank
    position: fixed
    width: 100%
    top: 88px
    bottom: 0
    .toplist
      height: 100%
      overflow: hidden
      .item
        display: flex
        margin: 0 20px
        padding-top: 20px
        height: 100px
        &:last-child
          padding-bottom: 20px
        .icon
          flex: 0 0 100px
          width: 100px
          height: 100px
        .songlist
          flex: 1
          display: flex
          flex-direction: column
          justify-content: center
          padding: 0 20px
          height: 100px
          overflow: hidden
          background: $color-highlight-background
          color: $color-text-d
          font-size: $font-size-small
          .song
            no-wrap()
            color:#FFF
            line-height: 26px
      .loading-container
        position: absolute
        width: 100%
        top: 50%
        transform: translateY(-50%)
</style>